
// <copyright file="GenericComponentController.cs" company="Subhadra Software Solutions">
//   
// </copyright>
// <summary>
//   The controller action delegate.
// </summary>

namespace SubhadraSolutions.Sharp.Utils
{
    using SubhadraSolutions.Sharp.Utils.Validation;

    /// <summary>
    /// The controller action delegate.
    /// </summary>
    public delegate void ControllerActionDelegate();

    /// <summary>
    /// The generic component controller.
    /// </summary>
    public class GenericComponentController : AbstractComponentController
    {
        #region Fields

        /// <summary>
        /// The pause callback.
        /// </summary>
        private readonly ControllerActionDelegate _pauseCallback;

        /// <summary>
        /// The resume callback.
        /// </summary>
        private readonly ControllerActionDelegate _resumeCallback;

        /// <summary>
        /// The start callback.
        /// </summary>
        private readonly ControllerActionDelegate _startCallback;

        /// <summary>
        /// The stop callback.
        /// </summary>
        private readonly ControllerActionDelegate _stopCallback;

        #endregion Fields

        #region Constructors and Finalizers

        /// <summary>
        /// Initializes a new instance of the <see cref="GenericComponentController"/> class.
        /// </summary>
        /// <param name="startCallback">
        /// The start callback.
        /// </param>
        /// <param name="stopCallback">
        /// The stop callback.
        /// </param>
        public GenericComponentController(ControllerActionDelegate startCallback, ControllerActionDelegate stopCallback)
            : base(false)
        {
            Guard.ArgumentNotNull(startCallback, "startCallback");
            Guard.ArgumentNotNull(stopCallback, "stopCallback");
            this._startCallback = startCallback;
            this._stopCallback = stopCallback;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="GenericComponentController"/> class.
        /// </summary>
        /// <param name="startCallback">
        /// The start callback.
        /// </param>
        /// <param name="stopCallback">
        /// The stop callback.
        /// </param>
        /// <param name="pauseCallback">
        /// The pause callback.
        /// </param>
        /// <param name="resumeCallback">
        /// The resume callback.
        /// </param>
        public GenericComponentController(ControllerActionDelegate startCallback, ControllerActionDelegate stopCallback, ControllerActionDelegate pauseCallback, ControllerActionDelegate resumeCallback)
            : base(true)
        {
            Guard.ArgumentNotNull(startCallback, "startCallback");
            Guard.ArgumentNotNull(stopCallback, "stopCallback");
            Guard.ArgumentNotNull(resumeCallback, "pauseCallback");
            Guard.ArgumentNotNull(resumeCallback, "resumeCallback");
            this._startCallback = startCallback;
            this._stopCallback = stopCallback;
            this._pauseCallback = pauseCallback;
            this._resumeCallback = resumeCallback;
        }

        #endregion Constructors and Finalizers

        #region Methods

        /// <summary>
        /// The pause.
        /// </summary>
        protected override void pause()
        {
            this._pauseCallback();
        }

        /// <summary>
        /// The resume.
        /// </summary>
        protected override void resume()
        {
            this._resumeCallback();
        }

        /// <summary>
        /// The start.
        /// </summary>
        protected override void start()
        {
            this._startCallback();
        }

        /// <summary>
        /// The stop.
        /// </summary>
        protected override void stop()
        {
            this._stopCallback();
        }

        #endregion Methods
    }
}
